module Entities

	def self.encode(s)
		s.gsub(/[<>&"]/) {|m| { '<' => '&lt;', '>' => '&gt;', '&' => '&amp;', '"' => '&quot;'}[m] || m}
	end

	def self.decode(s)
		s.gsub(/&([a-z]{2,4});/i) {|m| {'amp' => '&', 'quot' => '"', 'lt' => '<', 'gt' => '>'}[$1] || m}
	end

end

